<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
    <script>
        //声明 async 函数
        async function main(){
            //声明一个 promise 对象
            let p = new Promise((resolve, reject) => {
                setTimeout(() => {
                    //成功
                    resolve("OKOKOK");
                    //失败
                    // reject('Error');
                }, 2000)
            });

            try{
                //使用 await 表达式  『wait 等待的意思』
                let res = await p;
                //输出结果
                console.log(res);
            }catch(e){
                console.log(e);
            }
        }

        main();


    </script>
</body>
</html>